using System;
using System.IO;
using System.Xml;

using Icodeon.Util;

namespace Icodeon
{
    public class BaseTest
    {
        string path;
        protected DirectoryInfo rootDirectory;
        protected DirectoryInfo scormPackageDirectory;
        protected DirectoryInfo commonCartridgeDirectory;
        protected DirectoryInfo scorm2ccDirectory;
        protected FileInfo xslFile;
        protected XmlElement manifest;
        protected DirectoryInfo temp;

        public BaseTest()
        {
            this.path = @"C:\Users\icodeon\Documents\icodeon\projects\scorm2cc\codeplex";
            //this.path = @"C:\Documents and Settings\Icodeon\My Documents\icodeon\projects\scorm2cc\codeplex";
            this.rootDirectory = new DirectoryInfo(path);
            this.temp = new DirectoryInfo(System.Environment.ExpandEnvironmentVariables("%TEMP%"));
        }

        protected void SetUp()
        {

            IOUtils ioUtils = new IOUtils();

            DirectoryInfo scormPackages =
                ioUtils.CombineParentAndChildDirectoryNames(this.rootDirectory, "packages");
            DirectoryInfo sourceDirectory = ioUtils.CombineParentAndChildDirectoryNames(scormPackages, "scorm_1p2_sco");

            this.scormPackageDirectory = ioUtils.CombineParentAndChildDirectoryNames(this.temp, "scorm/" + Guid.NewGuid().ToString());
            ioUtils.MakeDirectoriesInPath(this.scormPackageDirectory);

            Directory.Delete(this.scormPackageDirectory.FullName, true);

            System.Console.WriteLine("Copying to: " + this.scormPackageDirectory.FullName);
            xDirectory.Copy(sourceDirectory, this.scormPackageDirectory, true);

            this.commonCartridgeDirectory =
                ioUtils.CombineParentAndChildDirectoryNames(this.rootDirectory, @"tests\cc");
            this.scorm2ccDirectory =
                ioUtils.CombineParentAndChildDirectoryNames(this.rootDirectory, "scorm2cc");

            DirectoryInfo xslDirectory = ioUtils.CombineParentAndChildDirectoryNames(this.rootDirectory, "xsl");
            this.xslFile = ioUtils.CombineDirectoryNameAndFileName(xslDirectory, "scorm1.2cc.xslt");

            FileInfo imsManifestScorm = ioUtils.CombineDirectoryNameAndFileName(this.scormPackageDirectory, "imsmanifest.xml");
            XmlDocument doc = new XmlDocument();
            doc.Load(imsManifestScorm.FullName);

            this.manifest = doc.DocumentElement;
        }
    }
}
